home *** CD-ROM | disk | FTP | other *** search
/ PC World 2008 September / PCWorld_2008-09_cd.bin / v cisle / sadanastroju / wot-20080519-fx.xpi / chrome / wot.jar / content / cookies.js < prev    next >
Text File  |  2007-11-11  |  2KB  |  69 lines

  1. /*
  2.     cookies.js
  3.  
  4.     Copyright ┬⌐ 2006, 2007  Against Intuition, Inc. <info@mywot.com>
  5. */
  6.  
  7. const WOT_COOKIE_TIMEOUT = 10000;
  8. const WOT_COOKIE_TOPIC = "http-on-modify-request";
  9.  
  10. function wot_cookie_remover(request)
  11. {
  12.     this.channel = request.channel;
  13.  
  14.     this.service = Components.classes["@mozilla.org/observer-service;1"].
  15.                         getService(Components.interfaces.nsIObserverService);
  16.     this.service.addObserver(this, WOT_COOKIE_TOPIC, false);
  17.  
  18.     this.timeout = window.setTimeout(this.stop, WOT_COOKIE_TIMEOUT);
  19. }
  20.  
  21. wot_cookie_remover.prototype =
  22. {
  23.     channel: null,
  24.     service: null,
  25.     timeout: null,
  26.  
  27.     QueryInterface: function(iid)
  28.     {
  29.         if (!iid.equals(Components.interfaces.nsISupports) &&
  30.             !iid.equals(Components.interfaces.nsIObserver)) {
  31.             throw Components.results.NS_ERROR_NO_INTERFACE;
  32.         }
  33.  
  34.         return this;
  35.     },
  36.  
  37.     observe: function(subject, topic, data)
  38.     {
  39.         try {
  40.             if (topic == WOT_COOKIE_TOPIC && subject == this.channel) {
  41.                 this.channel.QueryInterface(Components.interfaces.nsIHttpChannel);
  42.                 this.channel.setRequestHeader("Cookie", "", false);
  43.                 this.stop();
  44.             }
  45.         } catch (e) {
  46.             dump("wot_cookie_remover.observe: failed with " + e + "\n");
  47.         }
  48.     },
  49.  
  50.     stop: function()
  51.     {
  52.         try {
  53.             if (this.timeout) {
  54.                 window.clearTimeout(this.timeout);
  55.                 this.timeout = null;
  56.             }
  57.  
  58.             if (this.service) {
  59.                 this.service.removeObserver(this, WOT_COOKIE_TOPIC);
  60.                 this.service = null;
  61.             }
  62.  
  63.             this.channel = null;
  64.         } catch (e) {
  65.             dump("wot_cookie_remover.stop: failed with " + e + "\n");
  66.         }
  67.     }
  68. };
  69.